Centos搭建本地yum源

您所在的位置:网站首页 yum本地源配置 centos Centos搭建本地yum源

Centos搭建本地yum源

2022-05-30 08:59| 来源: 网络整理| 查看: 265

为了减少公司内部大量vps使用外部yum源导致带宽不足情况,于是就搭建一台本地yum源服务器,通过脚本服务器定时去镜像站点更新yum数据。

1、建立yum源存放路径(本文以centos 7为例)

# mkdir /CentOS/7

2、获取镜像站点数据脚本(本文选用的是mirrors.ustc.edu.cn镜像站点) ps:下面代码中的'&&'实际使用中需要去掉''号

#!/bin/bash /usr/bin/rsync -avzL --exclude=addons --exclude=centosplus --exclude=contrib --exclude=cr --exclude=fasttrack --exclude=isos --exclude=RELEASE-NOTES* --exclude=i386 --exclude=*i386.rpm --exclude=repodata rsync://mirrors.ustc.edu.cn/centos/7/ /CentOS/7 for i in /CentOS/7/extras/x86_64 /CentOS/7/os/x86_64 /CentOS/7/updates/x86_64 ; do /bin/rm $i/repodata -rf && /usr/bin/createrepo -s sha --workers 8 $i ;done /usr/bin/rsync -avzL --exclude=i386 --exclude=ppc64 --exclude=repodata --exclude=repoview --exclude=SRPMS rsync://mirrors.ustc.edu.cn/epel/7 /CentOS/epel/ for i in /CentOS/epel/7/x86_64 ; do /bin/rm $i/repodata -rf '&&' /usr/bin/createrepo --worker 8 $i ;done

3、添加排程,定时去爬数据(flock是防止旧的排程没有结束,而新的排程有开始运行) ps:下面代码中'2>&1 >>'需要去掉''号

01 02 * * * flock -xn /tmp/mytest.lock -c '/bin/bash /CentOS/sysyum.sh '2>&1 >>'/dev/null'

4、替换repo文件

移除/etc/yum.repos.d路径下所有repo格式文件

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repos.old/ -f

在/etc/yum.repos.d路径下新建yum源文件

vim CentOS-Base.repo [base] name=CentOS-\$releasever - Base baseurl=http://ip:port/7/os/x86_64 gpgcheck=0 [updates] name=CentOS-\$releasever - Updates baseurl=http://ip:port/7/updates/x86_64 gpgcheck=0 [extras] name=CentOS-\$releasever - Extras baseurl=http://ip:port/7/extras/x86_64 gpgcheck=0

5、配置nginx(即第4步中url的ip和port)

server { listen port; server_name localhost; index index.html index.htm; root /CentOS; autoindex on; access_log logs/yum.access.log access; }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3